package com.ruoyi.web.invest.asset.moneytrack.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.invest.asset.moneytrack.domain.MoneyTrack;
import com.ruoyi.web.invest.asset.moneytrack.service.IMoneyTrackService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资金用途追踪Controller
 *
 * @author houxuzhong
 * @date 2021-08-25
 */
@RestController
@RequestMapping("/invert/asset/moneytrack")
public class MoneyTrackController extends BaseController
{
    @Autowired
    private IMoneyTrackService moneyTrackService;

    /**
     * 查询资金用途追踪列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MoneyTrack moneyTrack)
    {
        startPage();
        List<MoneyTrack> list = moneyTrackService.selectMoneyTrackList(moneyTrack);
        return getDataTable(list);
    }

    /**
     * 导出资金用途追踪列表
     */
    @Log(title = "资金用途追踪", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MoneyTrack moneyTrack)
    {
        List<MoneyTrack> list = moneyTrackService.selectMoneyTrackList(moneyTrack);
        ExcelUtil<MoneyTrack> util = new ExcelUtil<MoneyTrack>(MoneyTrack.class);
        return util.exportExcel(list, "资金用途追踪数据");
    }

    /**
     * 获取资金用途追踪详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(moneyTrackService.selectMoneyTrackById(id));
    }

    /**
     * 新增资金用途追踪
     */
    @Log(title = "资金用途追踪", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MoneyTrack moneyTrack)
    {
        return toAjax(moneyTrackService.insertMoneyTrack(moneyTrack));
    }

    /**
     * 修改资金用途追踪
     */
    @Log(title = "资金用途追踪", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MoneyTrack moneyTrack)
    {
        return toAjax(moneyTrackService.updateMoneyTrack(moneyTrack));
    }

    /**
     * 删除资金用途追踪
     */
    @Log(title = "资金用途追踪", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(moneyTrackService.deleteMoneyTrackByIds(ids));
    }
}
